// index.js
Component({
    options: {
        addGlobalClass: true,
    },
    /**
     * 组件的属性列表
     */
    properties: {
        show: {
            type: Boolean,
            value: false
        },
        exStyle: {
            type: Object,
            value: {}
        }
    },
    lifetimes: {
        ready() {
            const that = this;
            if(typeof that.loadingSuccess == 'function') {
                this.loadingSuccess( { type: 'ready'});
            }
        },
    },
    /**
     * 组件的初始数据
     */
    data: {
        timer: 0,
        showCancel: false,
    },
    observers: {
        "show"( val) {
            const that = this;
            let timer = 0;
            if (val) {
                timer = setTimeout(function () {
                    clearTimeout(that.data.timer);
                    that.setData({
                        showCancel: true,
                        timer: 0
                    })
                }, that.data.$state.loading.timeout);
                that.setData({
                    timer: timer
                })
            } else {
                if (that.data.timer) {
                    clearTimeout(that.data.timer);
                }
                that.setData({
                    showCancel: false,
                    timer: 0
                })
            }
        }
    },
    /**
     * 组件的方法列表
     */
    methods: {
        _cancel() {
            this.$store.setState({
                'loading.show': false
            })
        }
    }
})